//
//  QDMetroSuccessViewController.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/4.
//  Copyright © 2019 YueWen. All rights reserved.
//

import UIKit

/// 出站成功
final class QDMetroSuccessHeaderView: UIView {
    
    /// 出站成功的标题
    let imageView = UIImageView()
    /// 出站标签
    let titleLabel = UILabel()
    /// 显示 先乘后付扣款中
    let subtitleLabel = UILabel()
    /// 完成按钮
    let finishButton = UIButton()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        imageView.image = "station_result_success".namedImage
        
        titleLabel.text = "出站成功！"
        titleLabel.font = Font.regular.font(size: 20)
        titleLabel.textColor = QDColors.black
        
        subtitleLabel.text = "先乘后付扣款中"
        subtitleLabel.font = Font.light.font(size: 16)
        subtitleLabel.textColor = QDColors.black

        finishButton.setTitle("完成", for: .normal)
        finishButton.setTitleColor(#colorLiteral(red: 0.4352941176, green: 0.8392156863, blue: 0.5058823529, alpha: 1), for: .normal)
        finishButton.titleLabel?.font = Font.semibold.font(size: 16)
        finishButton.layer.cornerRadius = 24
        finishButton.layer.borderWidth = 0.5
        finishButton.layer.borderColor = QDColors.theme.cgColor
        finishButton.clipsToBounds = true
        
        addSubview(imageView)
        addSubview(titleLabel)
        addSubview(subtitleLabel)
        addSubview(finishButton)
        
        imageView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(104 + BarDistance.NavigationBar.safeDistance)
            make.width.height.equalTo(140)
            make.centerX.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.height.equalTo(28)
            make.top.equalTo(imageView.snp.bottom)
        }
        
        subtitleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.height.equalTo(22)
            make.top.equalTo(titleLabel.snp.bottom).offset(4)
        }
        
        finishButton.snp.makeConstraints { (make) in
            make.height.equalTo(48)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().inset(20)
            make.top.equalTo(subtitleLabel.snp.bottom).offset(84)
            
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}



/// 乘车码出站成功
final class QDMetroSuccessViewController: NWTableViewController {

    /// 成功的视图
    let headerView = QDMetroSuccessHeaderView()
    
    
    override func loadPropertysAtInitialization() {
        super.loadPropertysAtInitialization()
        
        headerRefreshEnable = false
        footerRefreshEnable = false
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        headerView.ritl_size = CGSize(width: ritl_width,
                                      height: 382 + 48 + 20 + BarDistance.NavigationBar.safeDistance)
        headerView.finishButton.addTarget(self, action: #selector(dismissAniamted), for: .touchUpInside)
        tableView.tableHeaderView = headerView
    }
    
    
    @objc func dismissAniamted(){
        dismiss(animated: true, completion: nil)
    }
}
